package chapter02.item01;

import java.lang.reflect.InvocationTargetException;

/**
 * @author zhaoyuqiang
 * @date 2021年09月22日 16:17
 * @description 第一条：用静态工厂方法代替构造器
 */
public class FoodFactory {
    public static Food getFood(String type) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Food food = null;

        food = (Food) Class.forName("chapter02.item01." + type).getDeclaredConstructor().newInstance();

        return food;
    }
}
